package com.example.yin.service.impl;

import com.example.yin.dao.CommentMapper;
import com.example.yin.domain.Comment;
import com.example.yin.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService{
    @Autowired
    private CommentMapper commentMapper;

    /*user module 用户模块*/
    @Override
    public boolean addComment(Comment comment) {
        comment.setCreateTime(new Date());
        comment.setUp((Integer)0);
        comment.setState((Integer)0);
        return commentMapper.addComment(comment);
    }

    @Override
    public boolean updateComment(Comment comment) {
        return commentMapper.updateComment(comment)>0;
    }

    @Override
    public boolean deleteComment(Integer id) {
        return commentMapper.deleteComment(id)>0;
    }

    @Override
    public List<Comment> selectCommentByUserId(Integer userId) {
        return commentMapper.selectCommentByUserid(userId);
    }


    @Override
    public List<Comment> selectCommentBySongId(Integer songId) {
        return commentMapper.selectCommentBySongid(songId);
    }

    @Override
    public List<Comment> selectApprovedCommentBySongid(Integer songId) {
        return commentMapper.selectApprovedCommentBySongid(songId);
    }

    @Override
    public boolean giveLikes(Integer id) {
        Comment comment = commentMapper.selectById(id);
        Integer ups = comment.getUp()+(Integer) 1;
        comment.setUp(ups);
        commentMapper.updateComment(comment);
        if(commentMapper.selectById(id).getUp()==ups)return true;
        else return false;
    }

    @Override
    public boolean cancelLikes(Integer id) {
        Comment comment = commentMapper.selectById(id);
        Integer ups = comment.getUp()-(Integer) 1;
        comment.setUp(ups);
        commentMapper.updateComment(comment);
        if(commentMapper.selectById(id).getUp()==ups)return true;
        else return false;
    }




    /*admin mudule 管理员模块*/
    @Override
    public List<Comment> allComment()
    {
        return commentMapper.allComment();
    }

    @Override
    public List<Comment> commentOfSongId(Integer songId) {
        return commentMapper.commentOfSongId(songId);
    }

//    @Override
//    public List<Comment> commentOfSongListId(Integer songListId) {
//        return null;
//    }

    @Override
    public boolean adminDeleteComment(Integer id) {
        return commentMapper.adminDeleteComment(id)>0;
    }

    @Override
    public boolean auditComment(Integer id, Integer state) {
        return commentMapper.auditComment(id, state) > 0;
    }

//    @Override
//    public List<Comment> commentOfSongId(Integer songId) {
//        return null;
//    }
//
//    @Override
//    public List<Comment> commentOfSongListId(Integer songListId) {
//        return null;
//    }
//

}
